home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 7
/
Aminet 7 - August 1995.iso
/
Aminet
/
comm
/
tcp
/
AmiMsgWin.lha
/
amimsgd
/
amimsgd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-22
|
3KB
|
126 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/syslog.h>
#include <netinet/in.h>
#include <lineread.h>
//#include <intuition/intuition.h>
#include <proto/dos.h>
#include <proto/exec.h>
//#include <proto/intuition.h>
char VersionTag[]="\0$VER: JoranAmimsgd 1.0 (14.12.93)";
struct AmiMsg {
struct MinNode am_Node;
char *am_user;
char *am_host;
char *am_msg;
struct sockaddr_in am_addr;
time_t am_time;
};
struct AmiMsgMsg {
struct Message amm_Msg;
struct AmiMsg amm_AmiMsg;
};
#define PORTNAME "JoranAmiMsgWin"
char user[15];
char host[20];
char msg[128];
char Title[80];
struct sockaddr_in his_addr;
long addrlen;
struct LineRead lr;
extern long server_socket;
long gethostname(char *,long len);
void main(void)
{
fd_set readfds;
int length,i;
struct AmiMsgMsg amm;
struct MsgPort *ReplyPort,*AmiMsgWinPort;
if(server_socket==-1) exit(20);
SetProgramName("JoranAmiMsgd");
addrlen = sizeof (his_addr);
if(getpeername(0,(struct sockaddr *)&his_addr, &addrlen)<0) exit(20);
// drie regels ophalen van het formaat
// HOST hostname:20
// USER username:10
// MSG message:40
initLineRead(&lr,server_socket,RL_LFREQNUL,160);
FD_ZERO(&readfds);
i=0;
while((i&7)!=7)
{
FD_SET(server_socket,&readfds);
if(select(server_socket+1,&readfds,NULL,NULL,NULL)<0) exit(20);
if(FD_SET(server_socket,&readfds))
{
length=lineRead(&lr);
if(length==-1) exit(20);
if(lr.rl_Line)
{
if(!strncmp("HOST ",lr.rl_Line,5))
{
strncpy(host,lr.rl_Line+5,sizeof(host));
host[sizeof(host)-1]='\0';
i|=1;
}
if(!strncmp("USER ",lr.rl_Line,5))
{
strncpy(user,lr.rl_Line+5,sizeof(user));
user[sizeof(user)-1]='\0';
i|=2;
}
if(!strncmp("MSG ",lr.rl_Line,4))
{
strncpy(msg,lr.rl_Line+4,sizeof(msg));
msg[sizeof(msg)-1]='\0';
i|=4;
}
}
}
}
CloseSocket(server_socket);
AmiMsgWinPort=NULL;
if(ReplyPort=CreatePort(NULL,0))
{
amm.amm_AmiMsg.am_user=user;
amm.amm_AmiMsg.am_host=host;
amm.amm_AmiMsg.am_msg=msg;
memcpy(&amm.amm_AmiMsg.am_addr,&his_addr,sizeof(struct sockaddr_in));
amm.amm_AmiMsg.am_time=time(0);
amm.amm_Msg.mn_ReplyPort=ReplyPort;
Forbid();
AmiMsgWinPort=FindPort(PORTNAME);
if(AmiMsgWinPort) PutMsg(AmiMsgWinPort,(struct Message *)&amm);
Permit();
if(AmiMsgWinPort) WaitPort(ReplyPort);
DeletePort(ReplyPort);
}
if(!AmiMsgWinPort)
syslog(LOG_INFO,"%s@%s(%s): %s",user,host,inet_ntoa(his_addr.sin_addr),msg);
}